import { request } from 'umi'

const getTags = () => {
  return request('/api/tags')
}

export default {
  // 每个module的标识符
  namespace: 'tags',

  // 状态
  state: {
    tagsList: []
  },

  // 调用服务器接口获取数据
  effects: {
    *fetchTags({ payload, callback }, { put, call }) {
      const res = yield call(getTags)

      // 生成action对象，传递给reducers
      yield put({
        type: 'setTagsList',
        payload: res
      })
    }
  },

  // 更新state
  reducers: {
    setTagsList(state, action) {
      return { ...state, tagsList: action.payload }
    }
  }

}